package com.maotai.app.util;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class DeviceUniqueID
{
  public static String BTMacID()
  {
	  return Build.INTERTSTATUS;
  }
  
  public static String CombinedDeviceID()
  {
	//IMEI
    String str1 = Build.IMEI;
    //很多信息的长度取值
    String localObject1 = getPseudoID();
    String localObject2 = Build.AndroidID;
    //wifi Mac 地址
    String str2 = Build.WIFIMAC;
    String paramContext = BTMacID();
    System.out.println("@m_szImei:" + str1 + " @m_szDevIDShort:" + (String)localObject1 + " @m_szAndroidID" + (String)localObject2 + " @m_szWLANMAC" + str2 + " @m_szBTMAC" + paramContext);
    localObject1 = str1 + (String)localObject1 + (String)localObject2 + str2 + paramContext;
    MessageDigest m = null;
    try {
        m = MessageDigest.getInstance("MD5");
    } catch(NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    m.update(localObject1.getBytes(), 0, localObject1.length());
    byte[] p_md5Data = m.digest();
    String m_szUniqueID = new String();
    StringBuffer tempB = new StringBuffer();
    for(int i = 0; i < p_md5Data.length; i ++) {
	    int b = p_md5Data[i] & 0xff;
	    if(b <= 0xf) {
            m_szUniqueID = "0";
        }else{
        	 m_szUniqueID = Integer.toHexString(b);
	         m_szUniqueID = m_szUniqueID.toLowerCase();
        }
	    tempB.append(m_szUniqueID);
    }
   
    return tempB.toString();
  }
  public static String CombinedDeviceID(String imei,String androidid,String macaddress,String interntstatus)
  {
	//IMEI
    String str1 = imei;
    //很多信息的长度取值
    String localObject1 = getPseudoID();
    String localObject2 = androidid;
    //wifi Mac 地址
    String str2 = macaddress;
    String paramContext = interntstatus;
    System.out.println("@m_szImei:" + str1 + " @m_szDevIDShort:" + (String)localObject1 + " @m_szAndroidID" + (String)localObject2 + " @m_szWLANMAC" + str2 + " @m_szBTMAC" + paramContext);
    localObject1 = str1 + (String)localObject1 + (String)localObject2 + str2 + paramContext;
    MessageDigest m = null;
    try {
        m = MessageDigest.getInstance("MD5");
    } catch(NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    m.update(localObject1.getBytes(), 0, localObject1.length());
    byte[] p_md5Data = m.digest();
    String m_szUniqueID = new String();
    StringBuffer tempB = new StringBuffer();
    for(int i = 0; i < p_md5Data.length; i ++) {
	    int b = p_md5Data[i] & 0xff;
	    if(b <= 0xf) {
            m_szUniqueID = "0";
        }else{
        	 m_szUniqueID = Integer.toHexString(b);
	         m_szUniqueID = m_szUniqueID.toLowerCase();
        }
	    tempB.append(m_szUniqueID);
    }
   
    return tempB.toString();
  }
 
  
  public static String getPseudoID()
  {
    try
    {
    	//BOARD 获取设备基板名称
    	//BRAND 获取设备品牌
    	//CPU_ABI 获取设备指令集名称（CPU的类型）
    	//DEVICE 获取设备驱动名称
    	//DISPLAY 获取设备显示的版本包（在系统设置中显示为版本号）和ID一样
    	//HOST 设备主机地址
    	//ID 设备版本号
    	//MANUFACTURER 获取设备制造商
    	//MODEL 获取手机的型号 设备名称
    	//PRODUCT 整个产品的名称
    	//TAGS 设备标签。如release-keys 或测试的 test-keys 
    	//TYPE 设备版本类型  主要为"user" 或"eng".
    	//USER 设备用户名 基本上都为android-build
      String localObject = Build.BOARD.length() % 10 + Build.BRAND.length() % 10 + Build.CPU_ABI.length() % 10 + Build.DEVICE.length() % 10 + Build.DISPLAY.length() % 10 + Build.HOST.length() % 10 + Build.ID.length() % 10 + Build.MANUFACTURER.length() % 10 + Build.MODEL.length() % 10 + Build.PRODUCT.length() % 10 + Build.TAGS.length() % 10 + Build.TYPE.length() % 10 + Build.USER.length() % 10+"";
      return localObject;
    }
    catch (Exception localException)
    {
      for (;;)
      {
        String str = "";
      }
    }
  }
  
  public static byte[] readFully(InputStream paramInputStream)
    throws IOException
  {
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    byte[] arrayOfByte = new byte['?'];
    for (;;)
    {
      int i = paramInputStream.read(arrayOfByte);
      if (i == -1) {
        return localByteArrayOutputStream.toByteArray();
      }
      localByteArrayOutputStream.write(arrayOfByte, 0, i);
    }
  }
  public static void main(String[] args){
	  String deviceId = CombinedDeviceID();
	  System.out.println(deviceId);
	  System.out.println(Md5Utils.getMD5Lower(("android-" + "1.0.21" + "-" + deviceId + "-" + "7c60b232d79d34d727c12c6f33ad8fea29ebb333ae0c1b3822e5a18934c8f189").toLowerCase()));
	  String UUID1 = "36ecb0f48aeee595d31cf0b2c7f0d724";
	  String UUID2 = "a08229b288a99b46dceae14dbbb6bbfb";
	  System.out.println(Md5Utils.getMD5Lower(("android-" + "1.0.21" + "-" + UUID1 + "-" + "7c60b232d79d34d727c12c6f33ad8fea29ebb333ae0c1b3822e5a18934c8f189").toLowerCase()));
	  
  }
}
